package com.mini.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;


@Data
@AllArgsConstructor
@NoArgsConstructor
public class BusinessResult<T> implements Serializable {

    private Long code;

    private String message;

    private T data;

    public static <T> BusinessResult createSuccessInstance(T data) {
        return new BusinessResult<>(CommonResultMessage.SUCCESS.code, CommonResultMessage.SUCCESS.message, data);
    }

    public static <T> BusinessResult createInstance(CommonResultMessage message) {
        return new BusinessResult<>(message.getCode(), message.getMessage(), null);
    }

    public static <T> BusinessResult createInstance(CommonResultMessage commonResultMessage, String message) {
        return new BusinessResult<>(commonResultMessage.getCode(), message, null);
    }

    public static <T> BusinessResult createInstance(CommonResultMessage message, T data) {
        return new BusinessResult<>(message.getCode(), message.getMessage(), data);
    }

    public static <T> BusinessResult createInstance(Long code, String message, T data) {
        return new BusinessResult<>(code, message, data);
    }
}
